package org.misalen.web.restful.job;

import org.json.JSONObject;
import org.misalen.web.restful.util.RetrofitUtil;
import org.misalen.web.restful.util.TypedInput;

import rx.Observable;
import rx.functions.Action1;

public class Item3 {
	public static final String baseRequest = "http://localhost:8080/misalen-web-server/";
	// public static final String baseRequest =
	// "http://47.93.57.192:8081/misalen-web-server/";

	public static final String version = "v1";
	public static String baseUrl = baseRequest + version + "/";

	public static final String mobile = "15032992879";

	public static void main(String[] args) {
		RetrofitUtil.setBaseUrl(baseUrl);
		// machinevideouserinfo();
		 machinevideolist();
		// machinevideorunningtime();
//		machinevideolocation();
	}

	public static Observable<JSONObject> machinevideouserinfo() {
		JSONObject json = new JSONObject();
		json.put("machineId", "headrestCode");
		json.put("type", "headrest");
		Observable<JSONObject> observable = RetrofitUtil.getService().machinevideouserinfo(TypedInput.buildJson(json));
		observable. // 结果
				subscribe(new Action1<JSONObject>() {
					@Override
					public void call(JSONObject weatherData) {
						System.out.println(weatherData);
					}
				}, new Action1<Throwable>() {
					@Override
					public void call(Throwable throwable) {
						System.err.println(throwable.getMessage());
					}
				});
		return observable;
	}

	public static Observable<JSONObject> machinevideolist() {
		JSONObject json = new JSONObject();
		json.put("userId", "402881ea5dd5232b015dd523a5bd0000");
		json.put("type", "headrest");
		System.err.println(TypedInput.buildJson(json));
		Observable<JSONObject> observable = RetrofitUtil.getService().machinevideolist(TypedInput.buildJson(json));
		observable. // 结果
				subscribe(new Action1<JSONObject>() {
					@Override
					public void call(JSONObject weatherData) {
						System.out.println(weatherData);
					}
				}, new Action1<Throwable>() {
					@Override
					public void call(Throwable throwable) {
						System.err.println(throwable.getMessage());
					}
				});
		return observable;
	}

	public static Observable<JSONObject> machinevideorunningtime() {
		JSONObject json = new JSONObject();
		json.put("userId", "402881ea5dd5232b015dd523a5bd0000");
		json.put("videoId", "4028b8815df04a92015df04bfccb0000");
		json.put("runningtime", 20);
		Observable<JSONObject> observable = RetrofitUtil.getService()
				.machinevideorunningtime(TypedInput.buildJson(json));
		observable. // 结果
				subscribe(new Action1<JSONObject>() {
					@Override
					public void call(JSONObject weatherData) {
						System.out.println(weatherData);
					}
				}, new Action1<Throwable>() {
					@Override
					public void call(Throwable throwable) {
						System.err.println(throwable.getMessage());
					}
				});
		return observable;
	}

	public static Observable<JSONObject> machinevideolocation() {
		JSONObject json = new JSONObject();
		json.put("userId", "402881ea5dd5232b015dd523a5bd0000");
		json.put("type", "headrest");
		json.put("longitude", "1.11111");
		json.put("latitude", "2.22222");
		Observable<JSONObject> observable = RetrofitUtil.getService().machinevideolocation(TypedInput.buildJson(json));
		observable. // 结果
				subscribe(new Action1<JSONObject>() {
					@Override
					public void call(JSONObject weatherData) {
						System.out.println(weatherData);
					}
				}, new Action1<Throwable>() {
					@Override
					public void call(Throwable throwable) {
						System.err.println(throwable.getMessage());
					}
				});
		return observable;
	}

}
